﻿using System;
using System.Data;
using Model.Data;
using Model;
using DataAccess;
using BusinessLogic.BusinessRules;


namespace BusinessLogic.ClassFactory
{
    /// <summary>
    /// ActionFactory 的摘要说明。
    /// </summary>
    public class ActionFactory : BaseFactory
    {
        public ActionFactory()
            : base()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        public ActionFactory(DBManager l_DBManager)
            : base(l_DBManager)
        {
        }
        public Action NewInstance()
        {
            ActionAccess l_Access = new ActionAccess(m_Manager);
            Action objAction = new Action(this.m_Manager, l_Access);
            objAction.NewDataSet();
            objAction.SelectRow(0);
            return objAction;
        }

        public Action CreatorBySql(string Sql)
        {
            ActionAccess l_Access = new ActionAccess(m_Manager);
            Action objAction = new Action(this.m_Manager, l_Access);
            DataSet l_ds = new ActionData();
            if (l_Access.QueryBySql(ref l_ds, Sql) < 1)
            {
                return null;
            }
            objAction.SetDataSet(l_ds);
            objAction.SelectRow(0);
            return objAction;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="intActionID"></param>
        /// <returns></returns>
        public Action Creator(int intActionID)
        {
            ActionAccess l_Access = new ActionAccess(m_Manager);
            Action objAction = new Action(this.m_Manager, l_Access);
            DataSet l_ds = new ActionData();
            if (l_Access.QueryByID(ref l_ds, intActionID) < 1)
            {
                return null;
            }
            objAction.SetDataSet(l_ds);
            objAction.SelectRow(0);
            return objAction;
        }

        public Action Creator()
        {
            ActionAccess l_Access = new ActionAccess(m_Manager);
            Action objAction = new Action(this.m_Manager, l_Access);
            DataSet l_ds = new ActionData();
            if (l_Access.QueryAll(ref l_ds) < 1)
            {
                return null;

            }
            objAction.SetDataSet(l_ds);
            objAction.SelectRow(0);
            return objAction;
        }

    }
}
